home *** CD-ROM | disk | FTP | other *** search
- Path: newsbf02.news.aol.com!not-for-mail
- From: razine@aol.com (Razine)
- Newsgroups: comp.lang.c
- Subject: revised code of calling a function twice from printf
- Date: 4 Mar 1996 17:51:16 -0500
- Organization: America Online, Inc. (1-800-827-6364)
- Sender: root@newsbf02.news.aol.com
- Message-ID: <4hfs54$k4e@newsbf02.news.aol.com>
- Reply-To: razine@aol.com (Razine)
- NNTP-Posting-Host: newsbf02.mail.aol.com
-
- Here is the actual code , modified with everyone's suggestions. However
- there is still a bug in here somewhere. Can anyone please explain what is
- wrong with this.
-
- It returns
-
- [1] NONE [2] NE
-
- I would like it to return
-
- [1] NONE [2] Asprin
-
- Thank you very much for your help. it is greatly appreciated.
-
-
- #include <stdio.h>
- #include <string.h>
-
- char *display_drug_type(int drug_index);
-
- int drug_inventory[5]={0,1,0,0,0};
-
- int main() {
-
- printf("[1] %s [2] %s
- \n",display_drug_type(0),display_drug_type(1));
-
- return 0;
- }
-
- char *display_drug_type(int drug_index) {
- char drug_type[81]="\0";
-
- switch(drug_inventory[drug_index]) {
- case 0 : strcpy(drug_type,"NONE"); break;
- case 1 : strcpy(drug_type,"Asprin"); break;
- default : printf("Error in Display_drug_inventory");
- }
- return drug_type;
- }
-
-